package com.mengya.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 用于数据库管理
 * 
 */
public class DBOpenHelper extends SQLiteOpenHelper {

	private static final int VERSON = 1;
	// //开启外键
	private String ON = "PRAGMA foreign_keys = ON";
	// //创建表file
	private String SQL1 = "create table if not exists file("
			+ "id 	integer	primary key," + "category	varchar(50)	not null,"
			+ "name	varchar(50)	not null," + "url varchar(100) not null,"
			+ "type varchar(10) not null," + "update_time timestamp not null,"
			+ "start_length long not null," + "size long not null,"
			+ "status integer default 2," + "is_collect	integer	default 0"
			+ ")";
	// //创建表file_review
	 private String SQL2 =
	 "create table if not exists file_review("+
	 "id integer primary key,"+
	 "first_read_time timestamp,"+
	 "last_read_time timestamp,"+
	 "is_read integer default 0"+
//	 "FOREIGN KEY(id) REFERENCES file(id) ON DELETE RESTRICT ON UPDATE CASCADE"+
	 ")";
	// 创建表test
	 private String SQL3 =
	 "create table if not exists test("+
	 "file_id	integer,"+
	 "id	integer,"+
	 "content	varchar(500)	not null,"+
	 "choice	varchar(500)	not null,"+
	 "da_an	varchar(50)	not null,"+
	 "is_pass	integer	default ,0"+
	 "type	varchar(1)	not null"+
//	 "FOREIGN KEY(file_id) REFERENCES file(id) ON DELETE RESTRICT ON UPDATE CASCADE,"+
//	 "primary key(file_id,id)"+
"primary key(id)"+
	 ")"  ;
	// 创建表notice
	private String SQL4 = "create table if not exists  notice("
			+ "id	integer		primary	key," + "title	varchar(100)	not null,"
			+ "content	varchar(100)	not null,"
			+ "public_time	varchar(50)	not null,"
			+ "public_depart	varchar(20)	not null,"
			+ "is_read	integer	default 0" + ")";
	private String deletetable = "drop table   notice  ";

	// 创建表download_recored
	 private String SQL5 =
	 "create table download_recored("+
	 "sn integer primary key,"+
	 "res_sn integer unique not null,"+
	 "res_name varchar(50) unique not null,"+
	 "download_url vachar(100) not null,"+
	 "is_finish integer not null default 0,"+
	 "down_time timestamp not null,"+
	 "resource_id integer not null"+
	 "resource_name varchar(50) not null"+
	 ")";

	public DBOpenHelper(Context context, String name, CursorFactory factory,
			int version) {
		// TODO Auto-generated constructor stub
		super(context, name, factory, version);
	}

	public DBOpenHelper(Context context, String name, int verson) {
		// TODO Auto-generated constructor stub
		this(context, name, null, verson);
	}

	public DBOpenHelper(Context context, String name) {
		// TODO Auto-generated constructor stub
		this(context, name, VERSON);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(ON);
//		db.execSQL(deletetable);
		db.execSQL(SQL1);
		 db.execSQL(SQL2);
		 db.execSQL(SQL3);
		db.execSQL(SQL4);
		 db.execSQL(SQL5);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

}
